1

    var words = [];

2

    var locationsSuffix = ["Road", "Drive", "Street", "Park", "Lane", "Avenue", "Quarter", "Reserve", "Tunnel", "Station", "Waterfront", "Railway", "Railways", "Transport"];

3

    var locationsPrefix = ["Creation of", "Development of", "Redevelopment of", "Regeneration of"];

4

5

    var walkDOM = function (node, func) {

6

        func(node);

7

        node = node.firstChild;

8

        while (node) {

9

            walkDOM(node, func);

10

            node = node.nextSibling;

11

        }

12

    };

13

14

    walkDOM(document.getElementsByClassName('project-results')[0], function (node) {

15

        if (node.nodeName === '#text') {

16

            var text = node.textContent;

17

            text = text.replace(/[^A-Za-z]/g, ' ');

18

            text = text.split(' ');

19

            if (text.length) {

20

                for (var i = 0, length = text.length; i < length; i += 1) {

21

                    var matched = false,

22

                        word = text[i];

23

                    if (isInArray(locationsSuffix, word) || isInArray(locationsPrefix, word)) {

24

                        var pos = node.data.indexOf(word);

25

                        var cut = node.data.substring(0, pos - 1);

26

                        var last = cut.lastIndexOf(" ");

27

                        var area = node.data.substring(pos, last);

28

29

                        if (isInArray(locationsSuffix, word)) {

30

                            var est = document.createElement('td');

31

                            var c = node.parentNode.parentNode.parentNode.appendChild(est);

32

                            est.innerHTML = area + " " + word + "";

33

                        } else if (isInArray(locationsPrefix, word)) {

34
●

                            var est = document.createElement('td');

35
●

                            var c = node.parentNode.parentNode.appendChild(est);

36

                            est.innerHTML = area + "";

37

                        }

38

39

                        var element = document.createElement('mark');

40

                        var b = node.parentNode.appendChild(element);

41

                        b.appendChild(node);

42

                        break;

43

                    }

44

                    for (var j = 0, numberOfWords = words.length; j < numberOfWords; j += 1) {

45

                        if (words[j][0] === word) {

46

                            matched = true;

47

                            words[j][1] += 1;

48

                        }

49

                    }

50

                    if (!matched) {

51

                        words.push([word, 1]);

52

                    }

53

                }

54

            }

55

        }

56

    });

57

58

    var displayWordList = function (words) {

59

        for (var i = 0, length = words.length; i < length; i += 1) {}

60

    };

61

62

    displayWordList(words);

63

64

    function isInArray(a, x) {

65

        return a.indexOf(x) > -1;

66

    }